package org.idontknow.pbs.cyclelength;

import org.idontknow.logger.Trace;
import org.idontknow.logger.TraceFactory;

import java.io.*;
import java.util.StringTokenizer;

class CycleLength {

	public static Trace log = TraceFactory.getTrace();

	public static void main(String[] args) {

		CycleLength obj = new CycleLength();
		String numString;

		try {
			BufferedReader br = new BufferedReader(
					new FileReader(System.getProperty("user.dir")
							+ File.separator + "src" + File.separator + "org"
							+ File.separator + "idontknow" + File.separator
							+ "pbs" + File.separator + "cyclelength"
							+ File.separator + "input"));
			String line;
			
			int iter = Integer.parseInt(br.readLine());
			log.info(iter);

			// line = br.readLine();

//			while (!((line = br.readLine()) != null)) {
			for (int i = 0; i < iter; i++) {
				line = br.readLine();
				log.info(line);
				
				StringTokenizer st = new StringTokenizer(line);
				int max = 0;
				int lowerBound = 0;
				int upperBound = 0;
				numString = st.nextToken();
				lowerBound = Integer.parseInt(numString);
				numString = st.nextToken();
				upperBound = Integer.parseInt(numString);

				// if (st.hasMoreTokens())
				// lowerBound = Integer.parseInt(st.nextToken());
				// if (st.hasMoreTokens())
				// upperBound = Integer.parseInt(st.nextToken());

				for (int j = lowerBound; j <= upperBound; j++) {
					int temp = obj.algo(j);
					if (temp > max)
						max = temp;
				}
				System.out.println(max);
			}
		} catch (Exception e) {
			System.err.println(e.getClass());
			e.printStackTrace();
			// System.err.println("IO Exception!");
		}
	}

	public int algo(int n) {
//		System.out.printf("%7d", n);
		int count = 1;
		while (!(n == 1)) {
			count++;
			if (n % 2 == 0)
				n = n / 2;
			else
				n = n * 3 + 1;
		}
		return count;
	}
}
